package com.immunology.logic.validators;

abstract class FieldValidator {

	public FieldValidator() {
		super();
	}

	protected boolean validate(String field, String alphabet) {
		boolean result = true;

		for (int i = 0, j = 1; j <= field.length(); i++, j++) {
			if (alphabet.contains(field.subSequence(i, j))) {
				result = result & true;
			} else {
				result = result & false;
			}
		}
		return result;
	}

	protected boolean isFirstLetterInAlphabet(String field, String alphabet) {
		boolean result = false;
		String firstLetter = null;
		if (field.length() != 0) {
			firstLetter = field.substring(0, 1);
			if (validate(firstLetter, alphabet)) {
				result = true;
			}
		}
		return result;

	}

	protected int countApostrophes(String field) {
		int result = 0;
		char[] symbols = field.toCharArray();

		for (char symbol : symbols) {
			if (symbol == '\'') {
				result++;
			}
		}
		return result;
	}
}
